<?php
    session_start();
    require_once 'config/conexao.class.php';
    require_once 'config/crud.class.php';

    $con = new conexao(); // instancia classe de conxao
    $con->connect(); // abre conexao com o banco
    
    /*
     * VERIFICA USUÁRIO
     */
                if(isset($_POST['usua_email'])):
                    $consulta_usuario = mysql_query("SELECT * FROM ldct_usuario WHERE usua_email='".$_POST['usua_email']."' AND usua_perm=2 AND usua_ativo=1");

                    $usuario = @mysql_fetch_object($consulta_usuario);
                    if($usuario==NULL){
                        echo "<div class='alert alert-error'>
                            Não existe nenhum usuário ativo com este e-mail
                          </div>";
                    }else{
                        
                        if(md5($_POST['usua_senha'])==$usuario->usua_senha){
                            $_SESSION['user']=$usuario->usua_id;
                            header("Location: index.php");
                        }else{
                          echo "<div class='alert alert-error'>
                            Senha errada.
                          </div>";  
                        }
                    }
                endif;
?>
        
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link href="css/style.css" rel="stylesheet" media="screen">
        <!-- jQuery -->
        <script src="js/jquery-1.10.2.min.js"></script>
        
        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
        <script src="js/bootstrap.min.js"></script>

    </head>

    <body>
        <div id="container-principal" class="container">
            <div class="navbar">
                <div class="navbar-inner">
                  <a class="brand"><img src="img/logo_admin.png" border="0" /></a>
                  
                 
               </div>
             </div> 
            
            <form action="" method="POST" class="form-horizontal" style="width: 600px; margin: 0 auto">
            <fieldset>

            <!-- Form Name -->
            <legend>Login Administrativo</legend>

            <!-- Text input-->
            <div class="control-group">
              <label class="control-label" for="usua_email">e-mail</label>
              <div class="controls">
                <input id="usuar_email" name="usua_email" type="text" placeholder="" class="input-large" required="">

              </div>
            </div>

            <!-- Password input-->
            <div class="control-group">
              <label class="control-label" for="usua_senha">senha</label>
              <div class="controls">
                  <p><input id="usuar_senha" name="usua_senha" type="password" placeholder="" class="input-small" required="">
                      <button style="margin-left: 10px;" id="bt_logar" name="bt_logar" class="btn btn-primary">entrar</button>
                  </p>

              </div>
            </div>

            <!-- Button -->
            <div class="control-group">
              <label class="control-label" for="bt_logar"></label>
              <div class="controls">
                
              </div>
            </div>

            </fieldset>
            </form>
            
        </div><!--container-->